#include "table.h"

void explore(HashTable& h) {
  /*
  string cmd;
  int64 k, v;
  bool insert;
  while (1) {
    cin >> cmd;
    if (cmd == "a") {
      cin >> k >> v;
      *(h.Lookup(k, &insert)) = v;
      cout << "inserted " << k << " -> " << v << endl;
    }
    if (cmd == "clear") {
      h.Clear();
    }
    if (cmd == "d") {
      cin >> k;
      h.Delete(k);
      cout << "deleted " << k << endl;
    }
    if (cmd == "%") {
      cin >> k;
      uint64 *look = h.Lookup(k, false);
      if (!look) cout << "not found" << endl;
      else cout << k << " -> " << *look << endl;
    }
    if (cmd == "p") {
      cout << h.ToString() << endl;
    }
  }
  */
}

template <class V>
void explore(Table<V> & h) {
  string cmd;
  int64 k, v;
  bool insert;
  while (1) {
    cin >> cmd;
    if (cmd == "q") return;
    if (cmd == "a") {
      cin >> k >> v;
      h[k] = v;
      cout << "inserted " << k << " -> " << v << endl;
    }
    if (cmd == "clear") {
      h.h_.Clear();
    } 
    if (cmd == "commit") {
      h.Commit();
    }
    if (cmd == "d") {
      cin >> k;
      h.Delete(k);
      cout << "deleted " << k << endl;
    }
    if (cmd == "%") {
      cin >> k;
      uint64 *look = h % k;
      if (!look) cout << "not found" << endl;
      else cout << k << " -> " << *look << endl;
    }
    if (cmd == "p") {
      cout << h.ToString() << endl;
    }
  }
}

void AutomatedTableTest() {
  Table<uint64> t(1, false, NULL);
  for (uint64 i=0; i<100000000; i++) {
    t[i] = i;
  } 
  for (uint64 i=0; i<100000000; i++) {
    CHECK(t[i] == i);
  }
  cout << "Passed test " << endl;
}

/*
int main() {
  AutomatedTableTest();
  // InitJobQueue();

  Table<uint64> oh(1, false, NULL);
  Table<uint64> oh2(1, false, &oh);
  explore(oh);
  explore(oh2);
}
*/
